<?php

/**
 * Description of PortletFactory
 *
 * @author EADeveloper
 */
class PortletFactory {

    public static $portletLog = array();

    /**
     * Crea un nuevo portlet en base a una clase o a un key almacenado en la session
     * @param type $className
     * @param type $portKey
     * @return className 
     */
    public static function getPortlet($className = null, $portKey = null) {
        $instance = NULL;
        if (isset(self::$portletLog[$portKey])) {
            $instance = self::$portletLog[$portKey];
        } else
        if ($className != NULL) {
            $key = md5("easoft" . count(self::$portletLog));
            $instance = new $className();
            $instance->instanceKey = $key;
            self::$portletLog[$key] = $instance;
        }

        $instance->includePath = PORTLETS . DS . "views" . DS;
        return $instance;
    }

    /**
     * Guarda todos los portlets procesados al momento
     */
    public static function savePortlets() {
        $_SESSION[PORTLETS_DB] = serialize(self::$portletLog);
    }

    public static function rewritePorlet($prt) {
        self::$portletLog[$prt->instanceKey] = $prt;
        self::savePortlets();
    }

}

?>
